package com.atmc.controller;

import com.atmc.bean.Supplier;
import com.atmc.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.jws.WebParam;

@Controller
public class SupplierController {
    @Autowired
    SupplierService supplierService;

    //去添加页面
    @RequestMapping("/supplierinsert")
    public String supplierinsert(){

        return "supplier/supplierAdd";
    }

    //供应商添加一条数据
    @RequestMapping("/supplier/supplieradd")
    public String supplieradd(@RequestParam("supplier_name")String supplier_name,
                              @RequestParam("linkman")String linkman,
                              @RequestParam("phone") String phone,
                              @RequestParam("email") String email
                              ){
        Supplier supplier=new Supplier(null,supplier_name,linkman,phone,email,null,null);
        supplierService.insertOne(supplier);
        return "bill/insertsuccess";

    }
    //查询一个供应商信息返回当前页面
    @RequestMapping("/selectSupplierOne")
    public String selectSupplierOne(@RequestParam("supplier_name")String supplier_name,Model model){
        Supplier list = supplierService.selectOne(supplier_name);
        model.addAttribute("msg",list);
        return "supplier/notice-list";
    }
    //详情查询
    @RequestMapping("/tosupplierdetails/{supplier_name}")
    public String tosupplierdetails(@PathVariable("supplier_name")String supplier_name, Model model){
        Supplier supplier = supplierService.selectOne(supplier_name);
        model.addAttribute("supplier",supplier);

        return "supplier/supplierDetail";
    }


}
